<style>
  .picImg {
    width: 40px;
    height: 40px;
  }
</style>
<template>
  <div class="app-container">
    <div class="filter-container">
      <el-date-picker
        v-model="listQuery.startTime"
        align="right"
        type="datetime"
        placeholder="开始日期"
        :picker-options="pickerOptions"
        value-format="yyyy-MM-dd HH:mm:ss">
      </el-date-picker>
      -
      <el-date-picker
        v-model="listQuery.endTime"
        align="right"
        type="datetime"
        placeholder="结束日期"
        value-format="yyyy-MM-dd HH:mm:ss">
      </el-date-picker>
      <el-button type="primary" @click="getlistQuery">查询</el-button>
    </div>
    <el-table v-loading="listLoading" :data="list" element-loading-text="正在查询中。。。" border fit highlight-current-row
              @row-click="detail">

      <el-table-column fixed align="center" min-width="100" label="表单ID" prop="id"/>
      <el-table-column align="center" min-width="100" label="表单编号" prop="formNo"/>
      <el-table-column align="center" min-width="100" label="上传时间" prop="addTime"/>
      <el-table-column align="center" min-width="100" label="保险公司ID" prop="insuranceID"/>
      <el-table-column align="center" min-width="100" label="权益服务商ID" prop="insurserviceID"/>
      <el-table-column align="center" min-width="100" label="保理公司ID" prop="factoringID"/>
      <el-table-column align="center" min-width="100" label="保单总数" prop="billCount"/>
      <el-table-column align="center" min-width="100" label="服务费总额" prop="amount"/>
      <el-table-column align="center" min-width="100" label="表单状态" prop="status"/>
      <el-table-column align="center" min-width="100" label="权益服务商处理时间" prop="advanceTime"/>
      <el-table-column align="center" min-width="100" label="需要垫资保单数" prop="advanceCount"/>
      <el-table-column align="center" min-width="100" label="需要垫资金额" prop="advanceAmount"/>
      <el-table-column align="center" min-width="100" label="垫资支付时间" prop="advanceTime"/>
      <el-table-column align="center" min-width="100" label="回款总额" prop="repayAmount"/>
      <el-table-column align="center" min-width="100" label="回款时间" prop="repayTime"/>
      <el-table-column align="center" min-width="100" label="上传备注" prop="remarkUp"/>
      <el-table-column align="center" min-width="100" label="垫资申请备注" prop="remarkAdv"/>
      <el-table-column fixed="right" align="center" label="操作" width="200" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button type="primary" size="mini"
                     @click="handleEdit(scope.row)">垫资确认
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit"
                @pagination="getList"/>
    <el-dialog :visible.sync="editDialogVisible" title="表单明细">
      <!--<el-form ref="editForm" :model="editForm" status-icon label-position="left"-->
               <!--label-width="100px" style="width: 400px; margin-left:50px;">-->
        <!--<el-form-item label="表单ID">-->
          <!--<span>{{editForm.id}}</span>-->
        <!--</el-form-item>-->
        <!--<el-form-item label="保单号或合同号">-->
          <!--<span>{{editForm.billNo}}</span>-->
        <!--</el-form-item>-->
        <!--<el-form-item label="保单金额">-->
          <!--<span>{{editForm.billAmount}}</span>-->
        <!--</el-form-item>-->
        <!--<el-form-item label="权益服务费">-->
          <!--<span>{{editForm.fee}}</span>-->
        <!--</el-form-item>-->
        <!--<el-form-item label="小权益服务商统一信用代码">-->
          <!--<span>{{editForm.unicode}}</span>-->
        <!--</el-form-item>-->
        <!--<el-form-item label="是否需要垫资">-->
          <!--<span>{{editForm.isAdvance}}</span>-->
        <!--</el-form-item>-->
      <!--</el-form>-->
      <el-table v-loading="listLoading1" :data="list1" element-loading-text="正在查询中。。。" border fit highlight-current-row>
        <el-table-column align="center" min-width="100" label="表单ID" prop="id"/>
        <el-table-column align="center" min-width="100" label="保单号或合同号" prop="billNo"/>
        <el-table-column align="center" min-width="100" label="保单金额" prop="billAmount"/>
        <el-table-column align="center" min-width="100" label="权益服务费" prop="fee"/>
        <el-table-column align="center" min-width="100" label="小权益服务商统一信用代码" prop="unicode"/>
        <el-table-column align="center" min-width="100" label="是否需要垫资" prop="isAdvance"/>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="editDialogVisible = false">确定</el-button>
      </div>
    </el-dialog>
    <el-dialog :visible.sync="editDialogVisible1" title="表单明细">
      <el-form ref="editForm" :model="editForm" status-icon label-position="left"
               label-width="100px" style="width: 400px; margin-left:50px;">
        <el-form-item label="表单ID">
          <span>{{editForm.id}}</span>
        </el-form-item>
        <el-form-item label="保单号或合同号">
          <span>{{editForm.billNo}}</span>
        </el-form-item>
        <el-form-item label="保单金额">
          <span>{{editForm.billAmount}}</span>
        </el-form-item>
        <el-form-item label="权益服务费">
          <span>{{editForm.fee}}</span>
        </el-form-item>
        <el-form-item label="小权益服务商统一信用代码">
          <span>{{editForm.unicode}}</span>
        </el-form-item>
        <el-form-item label="是否需要垫资">
          <span>{{editForm.isAdvance}}</span>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="editDialogVisible = false">确定</el-button>
        <el-button type="danger" @click="editDialogVisible = false">取消</el-button>
      </div>
    </el-dialog>
    <el-dialog :visible.sync="editDialogVisible1" title="表单明细">
      <el-form ref="editForm" :model="editForm" status-icon label-position="left"
               label-width="100px" style="width: 400px; margin-left:50px;">
        <el-form-item label="表单ID">
          <span>{{editForm.id}}</span>
        </el-form-item>
        <el-form-item label="保单号或合同号">
          <span>{{editForm.billNo}}</span>
        </el-form-item>
        <el-form-item label="保单金额">
          <span>{{editForm.billAmount}}</span>
        </el-form-item>
        <el-form-item label="权益服务费">
          <span>{{editForm.fee}}</span>
        </el-form-item>
        <el-form-item label="小权益服务商统一信用代码">
          <span>{{editForm.unicode}}</span>
        </el-form-item>
        <el-form-item label="是否需要垫资">
          <span>{{editForm.isAdvance}}</span>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="editDialogVisible = false">确定</el-button>
        <el-button type="danger" @click="editDialogVisible = false">取消</el-button>
      </div>
    </el-dialog>
    <el-dialog :visible.sync="editDialogVisible2" title="表单明细">
      <el-form ref="editForm" :model="editForm" status-icon label-position="left"
               label-width="100px" style="width: 400px; margin-left:50px;">
        <el-form-item label="表单ID">
          <span>{{editForm.id}}</span>
        </el-form-item>
        <el-form-item label="是否全部申请垫资">
          <span>{{editForm.billNo}}</span>
        </el-form-item>
        <el-form-item label="备注">
          <el-input v-model="editForm.remark" auto-complete="off"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="editDialogVisible = false">确定</el-button>
        <el-button type="danger" @click="editDialogVisible = false">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import {doGet, doPost} from '@/api'
  import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
  import checkPermission from '@/utils/permission' // 权限判断函数

  const FETCH_PAGE = 'qyservicefee.html';
  const FETCH_URL = {
    LIST: `${FETCH_PAGE}?op=list`,
    CREATE: `${FETCH_PAGE}?op=billlist`,
    EDIT: `${FETCH_PAGE}?op=formup`,
    DELETE: `${FETCH_PAGE}?op=formreup`,
    IMPORT: `${FETCH_PAGE}?op=interest`,
    BIG: `${FETCH_PAGE}?op=pay`
  }

  export default {
    name: 'qyservicefee',
    components: {Pagination},
    filters: {
//         accTyped: function(val){
//             return function (val){
//                 return {0: "服务费账户",1: "代付账户"}[val] || "未知"
//             }
//         },
    },
    data() {
      return {
        pickerOptions: {
          disabledDate(time) {
            return time.getTime() > Date.now();
          },
          shortcuts: [{
            text: '今天',
            onClick(picker) {
              picker.$emit('pick', new Date());
            }
          }, {
            text: '昨天',
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24);
              picker.$emit('pick', date);
            }
          }, {
            text: '一周前',
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', date);
            }
          }]
        },
        list: [],
        list1:[],
        total: 0,
        listLoading: true,
        listLoading1:true,
        listQuery: {
          startTime: undefined,
          endTime: undefined
        },
        editForm: {
          id: undefined,
          billNo: undefined,
          billAmount: undefined,
          fee: undefined,
          unicode: undefined,
          isAdvance: undefined,
        },
        editDialogVisible: false,
        editDialogVisible1: false,
        editDialogVisible2: false,
      }
    },
    created() {
      this.getList()
    },
    methods: {
      checkPermission,
      getList() {
        this.listLoading = true
        doGet(FETCH_URL.LIST, this.listQuery).then(response => {
          this.list = response.rows
          this.total = response.rows.length
          this.listLoading = false
        }).catch(() => {
          this.list = []
          this.total = 0
          this.listLoading = false
        })
      },
      handleEdit(row) {
        this.editDialogVisible2 = true
      },
      detail(row) {
        this.editDialogVisible = true
        this.listLoading1=true
//        console.log(row.id)
        doGet(FETCH_URL.CREATE, {id:row.id}).then(response => {
          this.list1=response.rows
//          console.log(response.rows);
          this.listLoading1=false
//          this.editForm.id = response.rows[0].id;
//          this.editForm.billNo = response.rows[0].billNo;
//          this.editForm.billAmount = response.rows[0].billAmount;
//          this.editForm.fee = response.rows[0].fee;
//          this.editForm.unicode = response.rows[0].unicode;
//          this.editForm.isAdvance = response.rows[0].isAdvance
        }).catch(() => {
          this.list = [];
          this.total = 0;
          this.listLoading1=false
        })
      },
      getlistQuery(){
        this.getList()
      }
    }
  }
</script>
